import request from 'umi-request';

export default {
    namespace: 'data',

    state: [],

    reducers: {
        update(_, { payload }) {
            const { datas } = payload;
            return datas;
        },
        deleteData(state, { payload }) {
            const { key: targetKey } = payload;

            return state.filter((e) => e.key !== targetKey);
        },
    },

    effects: {
        *getAll(_, { call, put }) {
            const response = yield call(request.get, '/api/datas');

            yield put({
                type: 'update',
                payload: {
                    datas: response,
                },
            });
        },
    },
};
